#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import os
import sys

execfile(os.path.join(sys.path[0], "framework.py"))

from orioluspith.packets.metareader import FileMetaReader, FileMetaReaderError
from unittest import TestCase, TestLoader, TextTestRunner

class TestMeataFileReader(TestCase):
    def setUp(self):
        self.__reader = FileMetaReader()
        self.__workdir = os.path.join("./testdata/meta")
        
    def test_correct_file(self):
        path = os.path.join(self.__workdir, "correct_meta")
        meta = self.__reader.read(path)
                
        self.assertEqual("test_packet", meta.name)
        self.assertEqual("1.0.0.0", meta.version)
        self.assertEqual("Test packet for tests", meta.description)

        self.assertEqual(0, len(meta.conflicts))
        self.assertEqual(0, len(meta.replaces))
        self.assertEqual(0, len(meta.depends))        
    
    def test_invalid_file(self):
        path = os.path.join(self.__workdir, "invalid_meta")
        self.assertRaises(FileMetaReaderError, self.__reader.read, path)
    
    def test_missing_file(self):
        path = os.path.join(self.__workdir, "missing_meta")
        self.assertRaises(FileMetaReaderError, self.__reader.read, path)

if __name__ == "__main__":
    suite = TestLoader().loadTestsFromTestCase(TestMeataFileReader)
    TextTestRunner(verbosity=2).run(suite) 